//+------------------------------------------------------------------+
//| 最简单测试 - 验证基本线条显示                                        |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_label1  "Simple Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_width1  3

double SimpleBuffer[];

//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, SimpleBuffer, INDICATOR_DATA);
   // 不使用ArraySetAsSeries，使用MT5默认方式
   return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   if(rates_total < 5) return 0;
   
   // MT5标准方式：从prev_calculated开始计算
   int start = prev_calculated == 0 ? 0 : prev_calculated - 1;
   
   Print("=== 最简测试 ===");
   Print("rates_total=", rates_total, " prev_calculated=", prev_calculated, " start=", start);
   
   // 使用MT5标准的正向循环
   for(int i = start; i < rates_total; i++)
   {
      SimpleBuffer[i] = close[i];  // 直接复制收盘价
   }
   
   // 输出前几个值验证
   if(prev_calculated == 0)
   {
      Print("=== 数据验证 ===");
      for(int j = 0; j < MathMin(5, rates_total); j++)
      {
         Print("[", j, "] close=", close[j], " buffer=", SimpleBuffer[j]);
      }
      
      // 检查最后几个值
      Print("=== 最后几个值 ===");
      for(int j = MathMax(0, rates_total-5); j < rates_total; j++)
      {
         Print("[", j, "] close=", close[j], " buffer=", SimpleBuffer[j]);
      }
   }
   
   return rates_total;
}
//+------------------------------------------------------------------+